home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-1 / preproc.sit / pmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-19  |  4.5 KB  |  187 lines  |  [TEXT/MPS ]

  1. #include "::preproc:preproc.h"
  2. #include "::preproc:pproto.h"
  3.  
  4. char *progname = "pp";
  5.  
  6. /*
  7.  * The following code is operating-system dependent [@pmain.01]. Establish
  8.  *  command-line options.
  9.  */
  10.  
  11. #if PORT
  12. static char *ostr = "CPD:I:U:o:";
  13. static char *options = 
  14.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  15.    /* may need more options */
  16. Deliberate Syntax Error
  17. #endif                    /* PORT */
  18.  
  19. #if AMIGA || ATARI_ST || MACINTOSH || VM || MVS
  20. static char *ostr = "CPD:I:U:o:";
  21. static char *options = 
  22.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  23.    /* may need more options */
  24. Deliberate Syntax Error
  25. #endif                    /* AMIGA || ATARI_ST || ... */
  26.  
  27. #if MSDOS
  28. #if MICROSOFT || INTEL_386 || ZTC_386 || HIGHC_386 || WATCOM
  29.    /* this really isn't right for anything but Microsoft */
  30. static char *ostr = "CPD:I:U:o:A:Z:J";
  31. static char *options = 
  32.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile]\n    \
  33. [-A(S|C|M|L|H)] [-Za] [-J] [files]";
  34. #endif                    /* MICROSOFT || INTEL_386 || ...  */
  35.  
  36. #if TURBO
  37. static char *ostr = "CPD:I:U:o:m:p";
  38. static char *options = 
  39.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile]\n    \
  40. [-m(t|s|m|c|l|h)] [-p] [files]";
  41. #endif                    /* TURBO */
  42. #endif                    /* MSDOS */
  43.  
  44. #if UNIX || VMS
  45. static char *ostr = "CPD:I:U:o:";
  46. static char *options = 
  47.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  48. #endif                    /* UNIX || VMS */
  49.  
  50. /*
  51.  * End of operating-system specific code.
  52.  */
  53.  
  54. extern line_cntrl;
  55.  
  56. /*
  57.  * getopt() variables
  58.  */
  59. extern int optindex;        /* index into parent argv vector */
  60. extern int optopt;        /* character checked for validity */
  61. extern char *optarg;        /* argument associated with option */
  62.  
  63. int main(argc, argv)
  64. int argc;
  65. char **argv;
  66.    {
  67.    int c;
  68.    char *opt_lst;
  69.    char **opt_args;
  70.    int nopts;
  71.    FILE *out_file;
  72.  
  73.    /*
  74.     * By default, keep the image of white space, but replace each comment
  75.     *  by a space. By default, output #line directives.
  76.     */
  77.    whsp_image = NoComment;
  78.    line_cntrl = 1;
  79.  
  80.    /*
  81.     * The number of options that must be passed on to other phases
  82.     *  of the preprocessor are at most as large as the entire option
  83.     *  list.
  84.     */
  85.    opt_lst = (char *)alloc((unsigned int)argc);
  86.    opt_args = (char **)alloc((unsigned int)((sizeof (char *)) * argc));
  87.    nopts = 0;
  88.    out_file = stdout;
  89.  
  90.    /*
  91.     * Process options.
  92.     */
  93.    while ((c = getopt(argc, argv, ostr)) != EOF)
  94.       switch (c) {
  95.          case 'C':  /* -C - retan comments */
  96.             whsp_image = FullImage;
  97.             break;
  98.           case 'P': /* -P - do not output #line directives */
  99.             line_cntrl = 0;
  100.             break;
  101.          case 'D': /* -D<id><definition> - predefine an identifier */
  102.          case 'I': /* -I<path> - location to search for standard header files */ 
  103.          case 'U': /* -U<id> - undefine predefined identifier */
  104.  
  105. /*
  106.  * The following code is operating-system dependent [@pmain.02]. Accept
  107.  *  system specific options.
  108.  */
  109.  
  110. #if PORT
  111.    /* may need something */
  112. Deliberate Syntax Error
  113. #endif                    /* PORT */
  114.  
  115. #if AMIGA || ATARI_ST || MACINTOSH || VM || MVS
  116.    /* may need something */
  117. Deliberate Syntax Error
  118. #endif                    /* AMIGA || ATARI_ST || ... */
  119.  
  120. #if MSDOS
  121. #if MICROSOFT
  122.          case 'A':
  123.          case 'J':
  124.          case 'Z':
  125. #endif                    /* MICROSOFT */
  126.  
  127. #if TURBO
  128.          case 'm':
  129.          case 'p':
  130. #endif                    /* TURBO */
  131.  
  132. #if HIGHC_386 || INTEL_386 || ZTC_386 || WATCOM
  133.    /* something is needed */
  134. #endif                    /* HIGHC_386 || INTEL_386 || ... */
  135. #endif                    /* MSDOS */
  136.  
  137. #if UNIX || VMS
  138.    /* nothing is needed */
  139. #endif                    /* UNIX || VMS */
  140.  
  141. /*
  142.  * End of operating-system specific code.
  143.  */
  144.  
  145.             opt_lst[nopts] = c;
  146.             opt_args[nopts] = optarg;
  147.             ++nopts;
  148.             break;
  149.          case 'o': /* -o<file> - write output to this file */
  150.             out_file = fopen(optarg, "w");
  151.             if (out_file == NULL)
  152.                err2("cannot open output file ", optarg);
  153.             break;
  154.          default:
  155.             show_usage();
  156.          }
  157.  
  158.    opt_lst[nopts] = '\0';
  159.  
  160.    /*
  161.     * Scan file name arguments. If there are none, process standard input,
  162.     *  indicated by the name "-".
  163.     */
  164.    if (optindex == argc) {
  165.       init_preproc("-", opt_lst, opt_args);
  166.       output(out_file);
  167.       }
  168.    else {
  169.       while (optindex < argc)  {
  170.          init_preproc(argv[optindex], opt_lst, opt_args);
  171.          output(out_file);
  172.          optindex++;
  173.          }
  174.       }
  175.  
  176.    return NormalExit;
  177.    }
  178.  
  179. /*
  180.  * Print an error message if called incorrectly.
  181.  */
  182. novalue show_usage()
  183.    {
  184.    fprintf(stderr, "usage: %s %s\n", progname, options);
  185.    exit(ErrorExit);
  186.    }
  187.